package cn.zhouyafeng.itchat4j;

import cn.zhouyafeng.itchat4j.controller.MultiCoreLoginController;
import cn.zhouyafeng.itchat4j.core.MultiMsgCenter;
import cn.zhouyafeng.itchat4j.face.IMsgHandlerFace;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: ZhaoTao
 * \* Date: 2017/12/11
 * \* Time: 10:22
 * \* Description:
 * \
 */
public class MultiWechat {
    private static final Logger LOG = LoggerFactory.getLogger(Wechat.class);
    private IMsgHandlerFace msgHandler;
    public static ExecutorService LoginPool = Executors.newFixedThreadPool(10); //心跳检测线程池
    private String key;

    public MultiWechat(IMsgHandlerFace msgHandler, String qrPath,String key) {
        this.key = key;
        System.setProperty("jsse.enableSNIExtension", "false"); // 防止SSL错误
        this.msgHandler = msgHandler;

        // 登陆
        MultiCoreLoginController login = new MultiCoreLoginController(key);
        login.login(qrPath);
    }

    public void start() {
        LOG.info("+++++++++++++++++++开始消息处理+++++++++++++++++++++");
        new Thread(new Runnable() {
            @Override
            public void run() {
                MultiMsgCenter.handleMsg(msgHandler,key);
            }
        }).start();
    }
}
